<template>
  <div class="login">
    <div class="container">
      <a href="/#/index"><img src="/imgs/login-logo.png" alt=""></a>
    </div>
    <div class="wrapper">
      <div class="container">
        <div class="login-form">
          <h3>
            <span class="checked" @click="show=1">帐号登录</span><span class="sep-line">|</span><span @click="show=2" >账号注册</span>
          </h3>
          <div class="input">
            <input type="text" placeholder="请输入帐号" v-model="username">
          </div>
          <div class="input">
            <input type="password" placeholder="请输入密码" v-model="password">
          </div>
          <div class="btn-box">
            <a href="javascript:;" class="btn" @click="login" >登录</a>
          </div>
					<div class="btn-box">
					  <a href="javascript:;" class="btn1" @click="register" >注册</a>
					</div>
          <div class="tips">
            <div class="reg"><span></span>忘记密码？</div>
          </div>
        </div>
        <div class="login-form" :style="show==2?'display:block':'display:none'">
          <h3>
            <span  @click="show=1">帐号登录</span><span class="sep-line">|</span><span @click="show=2" class="checked" >账号注册</span>
          </h3>
          <div class="input">
            <input type="text" placeholder="请输入帐号" v-model="username">
          </div>
          <div class="input">
            <input type="password" placeholder="请输入密码" v-model="password">
          </div>
          <div class="btn-box">
            <a href="javascript:;" class="btn" @click="registerStart" >注册</a>
          </div>
					
        </div>
      </div>
    </div>
    <div class="footer">
      <div class="footer-link">
        <a href="" target="_blank">主页</a><span>|</span>
        <a href="" target="_blank">主页</a><span>|</span>
        <a href="" target="_blank">主页</a><span>|</span>
        <a href="" target="_blank">主页</a>
      </div>
      <p class="copyright">Copyright ©2019 mi.futurefe.com All Rights Reserved.</p>
    </div>
  </div>
</template>
<script>
	import {mapActions} from 'vuex';
export default {
	data(){
		return{
			username:'',
			password:'',
			userId:'',
			show:"2"
		}
	},
	methods:{
		login(){
			
			let {username,password}=this;
			this.axios.post('/user/login',{
				username,password
			}).then(res=>{
				console.log(res)
				//用cookie来存储登录信息
				this.$cookie.set('userId',res.id,{expires:'Session'})
				// this.$store.dispatch('saveUserName',res.username)
				this.saveUserName(res.username);
				this.$router.push({
					path:'/index',
					query:{
						from:'login'
					}
				})
			})
			this.username=""
			this.password=""
		},
		...mapActions(['saveUserName']),
		register(){
			this.show="2"
			
		},
		registerStart(){
			this.show="1"
			let {username,password}=this;
			this.axios.post('/user/register',{
				username,password
			}).then(res=>{
			alert("注册成功")
			})
			this.username=""
			this.password=""
		}
	}
  }
</script>
<style lang="less" scope>
.login{
  .container{
    height:113px;
		width: 1226px;
    img{
      width:auto;
      height:100%;
    }
  }
  .wrapper{
    background:url('/imgs/login-bg.jpg') no-repeat center;
		text-align: center;
    .container{
			display: inline-block;
			width: 1226px;
      height:576px;
			position: relative;
      .login-form{
        box-sizing: border-box;
        padding-left: 31px;
        padding-right: 31px;
        width:410px;
        height:510px;
        background-color:rgba(255,255,255,.86);
        position:absolute;
        bottom:29px;
        right:0;
        h3{
          line-height:23px;
          font-size:24px;
          text-align:center;
          margin:40px auto 49px;
          .checked{
            color:#FF6600;
          }
          .sep-line{
            margin:0 32px;
          }
        }
        .input{
          display:inline-block;
          width:348px;
          height:50px;
          border:1px solid #E5E5E5;
          margin-bottom:20px;
          line-height: 50px;
					font-size: 14px;
          input{
            width: 100%;
            height: 100%;
            border: none;
            padding: 0 18px;
						box-sizing: border-box;
          }
        }
        .btn{
          width:100%;
          line-height:50px;
          margin-top:10px;
          font-size:16px;
        }
				.btn1{
					display: inline-block;
					width:100%;
					line-height:50px;
					margin-top:10px;
					font-size:16px;
					background-color: #C0C4CC;
					color: #FFFFFF;
				}
        .tips{
          margin-top:14px;
          display:flex;
          justify-content:space-between;
          font-size:14px;
          cursor:pointer;
          .sms{
            color:#FF6600;
          }
          .reg{
            color:#999999;
            span{
              margin:0 7px;
            }
          }
        }
      }
    }
  }
  .footer{
    height:100px;
    padding-top:60px;
    color:#999999;
    font-size:16px;
    text-align:center;
    .footer-link{
      a{
        color:#999999;
        display:inline-block;
      }
      span{
        margin:0 10px;
      }
    }
    .copyright{
      margin-top:13px;
    }
  }
}
</style>
